﻿using System;
using System.Collections.Generic;
using System.Text;
using GraphAPI;
using GraphAPI.Model;
using System.Drawing;

namespace ClickFind
{
	public class ClickAlg : IAlgorithm
	{
		#region IAlgorithm Members

		public string Name
		{
			get { return "Поиск максимальной клики"; }
		}

		public string Description
		{
			get { return ""; }
		}

		public string Category
		{
			get { return ""; }
		}

		public System.Windows.Forms.Control Use(Graph graph)
		{
			Graph retGraph = new Graph(graph);
			click = new List<int>();

			for (int i = 0; i < retGraph.EntityCount; i++)
			{
				List<int> temp = buildCick(i, retGraph);
				if (temp.Count > click.Count) click = temp;
			}

			foreach (int i in click)
			{
				retGraph.Entitys[i].ColorMark = Color.Indigo;
			}

			return new ClickControl(retGraph);
		}

		#endregion

		private List<int> click;

		private List<int> buildCick(int startVertex, Graph graph)
		{
			List<int> ret = new List<int>();
			ret.Add(startVertex);

			for (int i = 0; i < graph.EntityCount; i++)
			{
				bool cond = false;
				foreach (int j in ret)
					if (j == i)
						cond = true;
				if (cond) continue;

				cond = true;
				foreach(int j in ret)
				{
					if (graph.FindRelation(graph.Entitys[j], graph.Entitys[i]) == null)
						cond = false;
				}
				if (cond)
					ret.Add(i);
			}

			return ret;
		}
	}
}
